import { Component, OnInit, ViewChild, ViewContainerRef, ComponentRef, ComponentFactoryResolver } from '@angular/core';
import { CostPageComponent } from "../content/cost-page/cost-page.component";
import { CostService } from "./cost.service";

@Component({
  selector: 'app-cost',
  templateUrl: './cost.component.html',
  styleUrls: ['./cost.component.scss'],
  providers: [CostService]
})
export class ProductCostComponent implements OnInit {
  // 费用流水页面
  @ViewChild("costPage", { read: ViewContainerRef })
  costPage: ViewContainerRef;
  costPageComponent: ComponentRef<CostPageComponent>;

  constructor(
    public costService: CostService,
    public resolver: ComponentFactoryResolver

  ) { }

  ngOnInit() {
    this.showCostPage();
  }
  // 费用流水页面
  showCostPage() {
    if (this.costPageComponent && this.costPageComponent.instance) {
      this.costPageComponent.destroy();
    }
    const costPageComponent = this.resolver.resolveComponentFactory(CostPageComponent);
    this.costPageComponent = this.costPage.createComponent(costPageComponent);
  }
}
